    {% extends "home.htm" %}
        
        {% block title %}
            Inserisci la tua gustosissima ricetta
        {% endblock %}

    {% block content %}
<script type="text/javascript">
    <!--
    function add_ingredient(){
        if ((document.forms["nuova_ricetta"].quantita.value != "")&&(document.forms["nuova_ricetta"].descrizione.value != "")){
            q = document.forms["nuova_ricetta"].quantita.value;
            d = document.forms["nuova_ricetta"].descrizione.value;
            document.forms["nuova_ricetta"].ing_list.value = document.forms["nuova_ricetta"].ing_list.value + q + " -> " + d + "\n";
            document.forms["nuova_ricetta"].quantita.value = "";
            document.forms["nuova_ricetta"].descrizione.value = "";
        }
        else{
            alert("Non accettiamo i campi vuoti !!")
        }
    }

    function clear_ingredients(){
        document.forms["nuova_ricetta"].ing_list.value = "";
    }

    function verify(id)
    {
        if(isNaN(id.value))
        {
             alert(id.name+' deve essere un numero !!');
             id.value='';
         }
    }
    -->
</script>
<h2>Ricetta</h2>
        <form name="nuova_ricetta" action="." method="Post">
            <table>
                <tr>  
                    <td> 
                        Nome ricetta
                    </td>
                    <td> 
                        <input type="text" name="ricetta" value="{{ nome }}">
                    </td>
                </tr>    
                <tr>
                    <td>
                        Area Geografica
                    </td>
                    <td>
                        <select name="cucina">
                            {% for i in cuisine %}
                                {% ifequal selec_cuisine i.name %}
                                    <option value="{{ i.id }}" selected>{{ i.name }}</option>
                                {% else %}
                                    <option value="{{ i.id }}">{{ i.name }}</option>
                                {% endifequal %}
                            {% endfor %}
                        </select>            
                </tr>
                <tr>  
                    <td> 
                        Categoria
                    </td>
                    <td> 
                        <select name="categoria">
                            {% for i in category %}
                                {% ifequal selec_category i.name %}
                                    <option value="{{ i.id }}" selected>{{ i.name }}</option>
                                {% else %}
                                    <option value="{{ i.id }}">{{ i.name }}</option>
                                {% endifequal %}
                            {% endfor %}
                        </select>
                    </td>
                </tr>
                <tr>  
                    <td> 
                        Stagione
                    </td>
                    <td> 
                        <select name="stagione">
                            {% for i in season %}
                                {% ifequal selec_season i.name %}
                                    <option value="{{ i.id }}" selected>{{ i.name }}</option>
                                {% else %}
                                    <option value="{{ i.id }}">{{ i.name }}</option>
                                {% endifequal %}
                            {% endfor %}
                        </select>
                    </td>
                </tr>
                <tr>
                    <td colspan="2" align="center">
                        <b>Ingredienti</b>
                    </td>
                </tr>
                <tr>
                    <td> 
                        Quantita' e u.m.
                    </td>
                    <td> 
                        Descrizione
                    </td>
                </tr>    
                <tr>  
                    <td> 
                        <input type="text" name="quantita" value="{{ quantita }}">
                    </td>
                    <td> 
                        <input type="text" name="descrizione" value="{{ descrizione }}">
                    </td>
                </tr>
                <tr>
                    <td colspan='2' align='center'>
                        <input id="button" name="submit_action" type="button" value="Aggiungi" onClick="add_ingredient()">
                        <input id="button" name="submit_action" type="button" value="Svuota Ingredienti"  onClick="clear_ingredients()">                
                    </td>
                </tr>
                <tr>
                    <td colspan='2'>
                        <textarea cols='53' rows='5' name="ing_list" readonly>{{ list }}</textarea>                
                    </td>
                </tr>    
                <tr>  
                    <td> 
                        Descrizione Preparazione
                    </td>
                </tr>
                <tr>
                    <td colspan='2'>
                        <textarea cols='53' rows='5' name="preparazione">{{ preparazione }}</textarea>
                    </td>
                </tr>
                <tr>  
                    <td> 
                        Tempo di preparazione (min)
                    </td>
                    <td> 
                        <input type="text" name="tempo" value="{{ tempo }}" onChange="verify(document.forms['nuova_ricetta'].tempo)">
                    </td>
                </tr>
                <tr>  
                    
                    <td> 
                        Facilita
                    </td>
                    <td>
                        {% for i in array %}
                            {% ifequal i facilita %}
                                 {{ i }}<input type="radio" name="difficolta" value="{{ i }}"checked="checked">
                            {% else %}
                                 {{ i }}<input type="radio" name="difficolta" value="{{ i }}">
                            {% endifequal %}
                        {% endfor %}
                    </td>
                </tr>
                <tr>  
                    <td> 
                        Calorie
                    </td>
                    <td> 
                        <input type="text" name="calorie" value="{{ calorie }}" onChange="verify(document.forms['nuova_ricetta'].calorie)">
                    </td>
                </tr>
                <tr>  
                    <td> 
                        Vino Consigliato
                    </td>
                    <td> 
                        <input type="text" name="vino" value="{{ vino }}">
                    </td>
                </tr>                
                <tr>  
                    <td colspan="2" align="center"> 
                        <input id="button" name="submit_action" type="submit" value="Continua">
                        <input id="button" name="submit_action" type="reset" value="Azzera Campi">
                    </td>
                </tr>                
            </table>
        </form>
    {% endblock %}
